package com.mall.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.DateUtils;
import com.mall.common.utils.SecurityUtils;
import com.mall.common.utils.StringUtils;
import com.mall.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.business.domain.TTxSq;
import com.mall.business.service.ITTxSqService;
import com.mall.common.core.page.TableDataInfo;

/**
 * 提现申请Controller
 *
 * @author ruoyi
 * @date 2025-03-31
 */
@RestController
@RequestMapping("/business/txsq" )
public class TTxSqController extends BaseController {
    @Autowired
    private ITTxSqService tTxSqService;

/**
 * 查询提现申请列表
 */
//@RequiresPermissions("business:txsq:list")
@GetMapping("/list" )
    public TableDataInfo list(TTxSq tTxSq) {
        startPage();
        List<TTxSq> list = tTxSqService.selectTTxSqList(tTxSq);
        return getDataTable(list);
    }

    /**
     * 导出提现申请列表
     */
    //@RequiresPermissions("business:txsq:export")
    @Log(title = "提现申请" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, TTxSq tTxSq) {
        List<TTxSq> list = tTxSqService.selectTTxSqList(tTxSq);
        ExcelUtil<TTxSq> util = new ExcelUtil<TTxSq>(TTxSq. class);
        util.exportExcel(response, list, "提现申请数据" );
    }

    /**
     * 获取提现申请详细信息
     */
    //@RequiresPermissions("business:txsq:query")
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(tTxSqService.getById(id));
    }

    /**
     * 新增提现申请
     */
    //@RequiresPermissions("business:txsq:add")
    @Log(title = "提现申请" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTxSq tTxSq) {
        return toAjax(tTxSqService.save(tTxSq));
    }

    /**
     * 修改提现申请
     */
    //@RequiresPermissions("business:txsq:edit")
    @Log(title = "提现申请" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTxSq tTxSq) {
        return toAjax(tTxSqService.updateById(tTxSq));
    }

    /**
     * 删除提现申请
     */
    //@RequiresPermissions("business:txsq:remove")
    @Log(title = "提现申请" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tTxSqService.removeByIds(Arrays.asList(ids)));
    }


    /**
     * @Author:zhaoyongke
     * @Description:
     */
    @PostMapping("checkXx")
    @Transactional
    public AjaxResult checkXx(@RequestBody TTxSq vo)
    {
        String checkStatus = vo.getCheckStatus();
        String checkRemark = vo.getCheckRemark();
        String id = vo.getId();
        if(StringUtils.isEmpty(id)){
            return  AjaxResult.error("参数获取失败");
        }
        if("3".equals(checkStatus)  && StringUtils.isEmpty(checkRemark)){
            return  AjaxResult.error("请填写审核备注");
        }
        TTxSq txjl = tTxSqService.getById(id);
        txjl.setCheckStatus(checkStatus);
        txjl.setCheckDate(DateUtils.getNowDate());
        txjl.setCheckUser(SecurityUtils.getUserId()+"");
        txjl.setCheckRemark(checkRemark);
        tTxSqService.updateById(txjl);
        // 扣除用户余额逻辑 后面再写
        return AjaxResult.success();
    }
}
